package com.kkd.kkdapp.fragment;

import java.text.DecimalFormat;

import android.animation.ObjectAnimator;
import android.animation.PropertyValuesHolder;
import android.app.Activity;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.Fragment;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationSet;
import android.view.animation.AnimationUtils;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.Gson;
import com.kkd.kkdapp.R;
import com.kkd.kkdapp.Notify.Const;
import com.kkd.kkdapp.Notify.NotifyDispatcher;
import com.kkd.kkdapp.activity.BindBankCardActivity;
import com.kkd.kkdapp.activity.CalendarActivity;
import com.kkd.kkdapp.activity.DealDetailsActivity;
import com.kkd.kkdapp.activity.ForTenderActivity;
import com.kkd.kkdapp.activity.HomeActivity;
import com.kkd.kkdapp.activity.HowToHappyCoinActivity;
import com.kkd.kkdapp.activity.InformationActivity;
import com.kkd.kkdapp.activity.KKDWebActivity;
import com.kkd.kkdapp.activity.MyActivity;
import com.kkd.kkdapp.activity.MyBlockActivity;
import com.kkd.kkdapp.activity.MyDiscountCouponActivity;
import com.kkd.kkdapp.activity.MyExperienceGoldActivity;
import com.kkd.kkdapp.activity.MyHappyCoinActivity;
import com.kkd.kkdapp.activity.MyIncomeActivity;
import com.kkd.kkdapp.activity.MyPlanActivity;
import com.kkd.kkdapp.activity.MyRecommendFriendActivity;
import com.kkd.kkdapp.activity.MyRegularDebtActivity;
import com.kkd.kkdapp.activity.MyTotalAssetsActivity;
import com.kkd.kkdapp.activity.RechargeActivity;
import com.kkd.kkdapp.activity.SignActivity;
import com.kkd.kkdapp.activity.WithdrawActivity;
import com.kkd.kkdapp.db.user.model.PrivilegeModel;
import com.kkd.kkdapp.http.entity.AhData;
import com.kkd.kkdapp.http.entity.AllAccountInfo;
import com.kkd.kkdapp.http.entity.MyProperty;
import com.kkd.kkdapp.http.entity.SingInData;
import com.kkd.kkdapp.http.entity.TyjConfigEntity;
import com.kkd.kkdapp.http.manager.HttpCallBack;
import com.kkd.kkdapp.http.manager.KkdHttpMagager;
import com.kkd.kkdapp.listener.OnSingleClickListener;
import com.kkd.kkdapp.utils.AppUtil;
import com.kkd.kkdapp.utils.CalendarUtil;
import com.kkd.kkdapp.utils.DialogUtils;
import com.kkd.kkdapp.utils.PreferenceUtils;
import com.kkd.kkdapp.utils.SystemUtils;
import com.kkd.kkdapp.view.CountView;
import com.kkd.kkdapp.view.CountViewFloat;
import com.kkd.kkdapp.view.CustomScrollView;
import com.kkd.kkdapp.view.CustomScrollView.OnRefreshListener;
import com.kkd.kkdapp.view.CustomScrollView.OnScrollListener;
import com.kkd.kkdapp.view.RoundImageView;
import com.nostra13.universalimageloader.core.ImageLoader;

public class WalletFragment extends Fragment implements OnClickListener {

	public static final int ON_GOT_PRIVILEGE = 1;// 获得特权本金

	private HomeActivity mHomeActivity;
	private RelativeLayout record; // 投标记录
	private TextView record_count;// 投标总额
	private TextView everydaty_count;
	public CountView experience_count;
	private TextView discount_count;
	private TextView bankid_tv;
	// private TextView manage_tv;
	private TextView safety_tips;
	private LinearLayout safety_line;
	// private RelativeLayout detail; // 交易明细
	private RelativeLayout bank_card_rl;// 安全银行卡
	private Button withdraw_bt; // 提现
	private Button recharge_bt; // 充值
	// private String version; // 当前App版本号
	private TextView mSign; // 签到
	private TextView mInviteCountTv; // 邀请好友收益
	private TextView calendar_count;
	private CountView mCurrency;
	private TextView mAddition;
	private boolean SIGNINFLAG = true;
	private TextView balance_tv; // 余额
	private CountViewFloat earnings_tv; // 总收益
	private RelativeLayout myproperty_top_img; // 头像
	private RelativeLayout symbol; // 消息中心
	private CustomScrollView mScrollView; // 下拉刷新
	private CountViewFloat property; // 总资产
	private TextView general; // 对话框总资产
	private MyProperty myProperty = new MyProperty();
	private AhData mAhData;
	private boolean PUPOPWINDOW;
	private boolean ISOPENPUPOPWINDOW;
	private int flag = 0;
	private RelativeLayout mEverydaty;
	private CalendarUtil tt;
	private TextView dot;
	private RoundImageView myproperty_header;
	private RelativeLayout discount; // 我的优惠券
	private TextView information_dot;
	private static long nLastTime = 0;
	private Dialog mDialog;
	private Toast mToast;
	private View mContentView;
	private ImageView tequan_tip;
	// private ExplosionField explosionField;
	private OnClickListener mOnClickListener;
	Handler handler = new Handler();
	private Dialog mDialog_signin;
	public static boolean flag_isExchangeHappBi;
	private ImageView icon_happy_sign;
	private ImageView icon_happy_sign_positive;
	private ObjectAnimator flip;
	private TextView tv_num_day_singed;
	private TextView deal_detail_tv;
	private RelativeLayout rel_sign;
	private View wallet_pull_bg;
	private int sumday;
	private String appsignRuleUrl;
	private ImageView myproperty_icon;
	DecimalFormat df_count = new DecimalFormat("#,###");
	private boolean isPropertyAnimator = true;
	private RelativeLayout invite_friends; // 邀请好友
	public static WalletFragment mWalletFragment;
	private View linear_flag_sigining;
	private boolean showHaveSignin = false;
	private View call_toService;
	private Dialog dialog_service;
	private RelativeLayout calendar_bt; // 还款日历

	Handler mHandler = new Handler() {

		@Override
		public void handleMessage(Message msg) {
			switch (msg.what) {
			case Const.NOTIFY_GOT_MYPROPERTY_SUCCESS_FLAG:
				displayCacheData();
				break;
			case ON_GOT_PRIVILEGE:
				updatePrivilegeTip();
				break;
			default:
				break;
			}
		}
	};

	@Override
	public void onAttach(Activity activity) {
		super.onAttach(activity);
		mHomeActivity = (HomeActivity) activity;
		NotifyDispatcher.getInstance().registerNotifyHandler(mHandler);
		isShowItem = PreferenceUtils.getInstance().getIsShowMyproperty(
				mHomeActivity);
		tt = new CalendarUtil();
	}

	@Override
	public void onDestroy() {
		super.onDestroy();
		NotifyDispatcher.getInstance().unRegisterNotifyHandler(mHandler);
		if (dialog_service != null) {
			dialog_service.cancel();
			dialog_service = null;
		}
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		initUI();
		mWalletFragment = this;
		return mContentView;
	}

	public View getContentView() {
		return mContentView;
	}

	private void initUI() {
		mContentView = LayoutInflater.from(mHomeActivity).inflate(
				R.layout.myproperty_fragment, null);
		calendar_bt = (RelativeLayout) mContentView
				.findViewById(R.id.calendar_bt);
		calendar_bt.setOnClickListener(this);
		wallet_pull_bg = mContentView.findViewById(R.id.wallet_pull_bg);
		rel_sign = (RelativeLayout) mContentView.findViewById(R.id.rel_sign);
		tequan_tip = (ImageView) mContentView.findViewById(R.id.tequan_tip);
		tequan_tip.setOnClickListener(this);
		tv_num_day_singed = (TextView) mContentView
				.findViewById(R.id.tv_num_day_singed);
		deal_detail_tv = (TextView) mContentView
				.findViewById(R.id.deal_detail_tv);
		int showTime = PreferenceUtils.getInstance().getJiaoyiShowTime(
				mHomeActivity);
		if (showTime < 3) {
			deal_detail_tv.setVisibility(View.VISIBLE);
			PreferenceUtils.getInstance().setJiaoyiShowTime(mHomeActivity,
					showTime + 1);
			Animation animation = AnimationUtils.loadAnimation(mHomeActivity,
					R.anim.deal_detail_tv_animation);
			deal_detail_tv.startAnimation(animation);
		}
		linear_flag_sigining = mContentView
				.findViewById(R.id.linear_flag_sigining);
		record = (RelativeLayout) mContentView.findViewById(R.id.record);
		// detail = (RelativeLayout) mContentView.findViewById(R.id.detail);
		bank_card_rl = (RelativeLayout) mContentView
				.findViewById(R.id.bank_card_rl);
		icon_happy_sign = (ImageView) mContentView
				.findViewById(R.id.icon_happy_sign);
		iconFilp();
		icon_happy_sign_positive = (ImageView) mContentView
				.findViewById(R.id.icon_happy_sign_positive);
		withdraw_bt = (Button) mContentView.findViewById(R.id.withdraw_bt);
		recharge_bt = (Button) mContentView.findViewById(R.id.recharge_bt);
		symbol = (RelativeLayout) mContentView.findViewById(R.id.symbol);
		mSign = (TextView) mContentView.findViewById(R.id.sign);
		mInviteCountTv = (TextView) mContentView
				.findViewById(R.id.invite_friends_count);
		calendar_count = (TextView) mContentView
				.findViewById(R.id.calendar_count);
		mCurrency = (CountView) mContentView.findViewById(R.id.happy_tv);
		mCurrency.setDecimalFormat(df_count);
		mAddition = (TextView) mContentView.findViewById(R.id.addition);
		mScrollView = (CustomScrollView) mContentView
				.findViewById(R.id.scrollview);
		// mScrollView.setHeaderBackgroundColor(0x00000000);
		mScrollView.setArrowImageView(R.drawable.xlistview_arrow_white);
		mScrollView.setGifDrawable(R.drawable.four_white_dot);
		property = (CountViewFloat) mContentView.findViewById(R.id.property);
		// property.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
		property.setDecimalFormat(new DecimalFormat("###,##0.00"));
		balance_tv = (TextView) mContentView.findViewById(R.id.balance_tv);
		earnings_tv = (CountViewFloat) mContentView
				.findViewById(R.id.earnings_tv);
		earnings_tv.setDecimalFormat(new DecimalFormat("###,##0.00"));
		myproperty_top_img = (RelativeLayout) mContentView
				.findViewById(R.id.myproperty_top_img);
		myproperty_header = (RoundImageView) mContentView
				.findViewById(R.id.myproperty_header);
		mEverydaty = (RelativeLayout) mContentView
				.findViewById(R.id.everydaty_rl);
		dot = (TextView) mContentView.findViewById(R.id.dot);
		discount = (RelativeLayout) mContentView.findViewById(R.id.discount);
		information_dot = (TextView) mContentView
				.findViewById(R.id.information_dot);
		record_count = (TextView) mContentView.findViewById(R.id.record_count);
		everydaty_count = (TextView) mContentView
				.findViewById(R.id.everydaty_count);
		experience_count = (CountView) mContentView
				.findViewById(R.id.experience_count);
		experience_count.setDecimalFormat(new DecimalFormat("#,###"));
		discount_count = (TextView) mContentView
				.findViewById(R.id.discount_count);
		bankid_tv = (TextView) mContentView.findViewById(R.id.bankid_tv);
		// manage_tv = (TextView) mContentView.findViewById(R.id.manage_tv);
		safety_tips = (TextView) mContentView.findViewById(R.id.safety_tips);
		safety_line = (LinearLayout) mContentView
				.findViewById(R.id.safety_line);
		invite_friends = (RelativeLayout) mContentView
				.findViewById(R.id.invite_friends);
		discount.setOnClickListener(this);
		record.setOnClickListener(this);
		// detail.setOnClickListener(this);
		bank_card_rl.setOnClickListener(this);
		mContentView.findViewById(R.id.earnings_line).setOnClickListener(this);
		mContentView.findViewById(R.id.experience_rl).setOnClickListener(this);
		mContentView.findViewById(R.id.happyBi_rl).setOnClickListener(this);
		mContentView.findViewById(R.id.balance_line).setOnClickListener(this);
		mContentView.findViewById(R.id.property_eye).setOnClickListener(this);
		mContentView.findViewById(R.id.property_rl).setOnClickListener(this);
		invite_friends.setOnClickListener(this);
		myproperty_icon = (ImageView) mContentView
				.findViewById(R.id.myproperty_icon);

		// mSign.setOnClickListener(new OnSingleClickListener() {
		//
		// @Override
		// public void onSingleClick(View v) {
		// // 签到
		// // 设置粒子扩散效果
		// // ParticleSystem particleSystem = new ParticleSystem(
		// // getActivity(), 100, R.drawable.sign, 800);
		// // particleSystem.setContext(getActivity());
		// // particleSystem.setSpeedRange(0.025f, 0.045f).oneShot(v, 50);
		// if (SIGNINFLAG) {
		// mSign.setEnabled(false);
		// signIn();
		// }
		// }
		// });
		// tv_num_day_singed.setOnClickListener(this);
		linear_flag_sigining.setOnClickListener(new OnSingleClickListener() {

			@Override
			public void onSingleClick(View v) {
				if (showHaveSignin) {
					SystemUtils.onEvent("Account_UnCheckIN", 1);
					Intent intent = new Intent(getActivity(),
							SignActivity.class);
					startActivity(intent);
				} else {
					if (SIGNINFLAG) {
						mSign.setEnabled(false);
						signIn();
					}
				}
			}
		});
		withdraw_bt.setOnClickListener(this);
		recharge_bt.setOnClickListener(this);
		myproperty_top_img.setOnClickListener(this);
		symbol.setOnClickListener(this);
		mEverydaty.setOnClickListener(this);
		safety_line.setOnClickListener(this);
		mScrollView.setOnRefreshListener(new OnRefreshListener() {
			public void onRefresh() {
				handler.postDelayed(new Runnable() {

					@Override
					public void run() {
						isPropertyAnimator = true;
						mHomeActivity.mymanage();
						mScrollView.onRefreshComplete();
					}
				}, 1000);

			}
		});
		mScrollView.setOnPullScrollListener(new OnScrollListener() {

			@Override
			public void onScroll(int scrollY) {
				LayoutParams parms = (LayoutParams) wallet_pull_bg
						.getLayoutParams();
				parms.topMargin = -SystemUtils.dip2px(mHomeActivity, 220)
						+ scrollY;
				wallet_pull_bg.setLayoutParams(parms);
			}
		});
		displayCacheData();
		if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
			View statebar = mContentView.findViewById(R.id.statebar);
			statebar.setVisibility(View.GONE);
		}

		call_toService = mContentView.findViewById(R.id.call_toService);
		call_toService.setOnClickListener(new OnSingleClickListener() {

			@Override
			public void onSingleClick(View v) {
				showDialog("客服电话：4000-137-000");
			}
		});
	}

	@Override
	public void onResume() {
		super.onResume();
		getOther();
		queryPrivilege();// 获取特权信息

		long nNow = System.currentTimeMillis();
		long nDiff = nNow - nLastTime;
		// if (nDiff > 600000 || flag_isExchangeHappBi) {
		// mymanage();
		nLastTime = nNow;
		// }
		if (PreferenceUtils.getInstance().getSignInFlag(getActivity()) == 1) {
			mAddition.setVisibility(View.GONE);
			// mSign.setClickable(false);---改过
			// mSign.setBackgroundResource(R.drawable.domyproperty_sign);
			mSign.setText(R.string.signed);
			rel_sign.setVisibility(View.INVISIBLE);
			tv_num_day_singed.setVisibility(View.VISIBLE);
			SIGNINFLAG = false;
			showHaveSignin = true;
		} else if (PreferenceUtils.getInstance().getSignInFlag(mHomeActivity) == 0) {
			mAddition.setVisibility(View.GONE);
			// mSign.setClickable(true);---改过
			// mSign.setBackgroundResource(R.drawable.myproperty_sign);
			mSign.setText(R.string.sign);
			rel_sign.setVisibility(View.VISIBLE);
			tv_num_day_singed.setVisibility(View.GONE);
			showHaveSignin = false;
			SIGNINFLAG = true;
		}

		updatePrivilegeTip();

	}

	private void updatePrivilegeTip() {
		PrivilegeModel nPrivilege = PrivilegeModel.getPrivilegeModel();
		if (nPrivilege != null
				&& nPrivilege.isHadPrivilege > nPrivilege.isShown) {
			tequan_tip.setVisibility(View.VISIBLE);
			ImageLoader.getInstance().displayImage(
					PrivilegeModel.findMyPrivilegeData().getPrivilegesQp(),
					tequan_tip);
			Animation animation = AnimationUtils.loadAnimation(mHomeActivity,
					R.anim.tequan_tip_animation);
			tequan_tip.startAnimation(animation);
		} else {
			tequan_tip.setVisibility(View.GONE);
		}
	}

	private void displayCacheData() {
		String json = PreferenceUtils.getInstance()
				.getMyproperty(mHomeActivity);
		if (!TextUtils.isEmpty(json)) {

			Gson gson = new Gson();
			AllAccountInfo mAllAccountInfo = gson.fromJson(json,
					AllAccountInfo.class);
			myProperty = mAllAccountInfo.getOtherData();
			mAhData = mAllAccountInfo.getAccHomeData().getAhData();
			updateUI();
			ISOPENPUPOPWINDOW = true;

		}
	}

	/**
	 * 签到接口
	 */
	public void signIn() {

		KkdHttpMagager.getInstance().getSignManager(SingInData.class,
				new HttpCallBack() {

					@Override
					public void onSuccess(int statusCode, Object responseBody) {
						AppUtil.stopProgressDialog();
						SingInData singInData = (SingInData) responseBody;
						int addHappyCurrency = singInData.getAddHappyCurrency();
						SIGN_ADDTION = addHappyCurrency; // 本次签到增加快乐币数量
						PreferenceUtils.getInstance().setSignInFlag(
								mHomeActivity, 1);
						// mymanage();
						// onSignClick();
						// mDialog_signin = DialogUtil.signInSuccessDialog2(
						// getActivity(), singInData.getCouponflag(),
						// singInData.getSummaryTop(),
						// singInData.getSummaryFooter(),
						// singInData.getAddHappyCurrency(),
						// singInData.getCouponDesc(),
						// singInData.getCouponAmount(),
						// WalletFragment.this);

						// mDialog_signin = DialogUtil.signInSuccessDialog3(
						// getActivity(), singInData.getSignInDays(),
						// singInData.getAddHappyCurrency(),
						// appsignRuleUrl, new OnSingleClickListener() {
						//
						// @Override
						// public void onSingleClick(View v) {
						// if (mDialog_signin != null) {
						// mDialog_signin.cancel();
						// mDialog_signin = null;
						// onSignClick();
						// mymanage();
						// }
						// }
						// });
						// mDialog_signin = DialogUtils.signInSuccessDialog4(
						// getActivity(), singInData.getSignInDays(),
						// singInData.getSummaryMiddle(),
						// singInData.getSummaryFooter(), appsignRuleUrl,
						// new OnSingleClickListener() {
						//
						// @Override
						// public void onSingleClick(View v) {
						// if (mDialog_signin != null) {
						// mDialog_signin.cancel();
						// mDialog_signin = null;
						// }
						// }
						// });
						mDialog_signin
								.setOnCancelListener(new OnCancelListener() {

									@Override
									public void onCancel(DialogInterface dialog) {
										onSignClick();
										mHomeActivity.mymanage();
									}
								});
						mSign.setEnabled(true);
					}

					@Override
					public void onFailure(int statusCode, String desc) {
						showToast(mHomeActivity, desc);
						if (statusCode == 226) {
							// mSign.setClickable(false);---改过
							// mSign.setBackgroundResource(R.drawable.domyproperty_sign);
							mSign.setText(R.string.signed);
							rel_sign.setVisibility(View.INVISIBLE);
							tv_num_day_singed.setVisibility(View.VISIBLE);
							showHaveSignin = true;
							mHomeActivity.mymanage();
						}
						AppUtil.stopProgressDialog();
						mSign.setEnabled(true);
					}
				});
	}

	private static int SIGN_ADDTION;
	private static final int DURATION = 300;

	private void onSignClick() {
		if (!mAddition.isShown()) {
			mAddition.setVisibility(View.VISIBLE);
			mAddition.setText("+" + SIGN_ADDTION);
		} else {
			return;
		}
		SystemUtils.onEvent("Account_CheckIN", 1);
		// button animation
		// mSign.setClickable(false);---改过
		// mSign.setBackgroundResource(R.drawable.domyproperty_sign);
		mSign.setText(R.string.signed);
		rel_sign.setVisibility(View.INVISIBLE);
		tv_num_day_singed.setVisibility(View.VISIBLE);
		showHaveSignin = true;
		// ScaleAnimation scaleAnimation = new ScaleAnimation(1f, 1.8f, 1f,
		// 1.8f,
		// Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
		// 0.5f);
		// scaleAnimation.setRepeatMode(Animation.REVERSE);
		// scaleAnimation.setRepeatCount(1);
		// scaleAnimation.setDuration(150);
		// scaleAnimation.setInterpolator(new AccelerateInterpolator());
		// mSign.startAnimation(scaleAnimation);

		int current = 0;
		try {
			current = Integer.parseInt(mCurrency.getText().toString());
		} catch (Exception e) {
			e.printStackTrace();
		}
		mCurrency.showNumberWithAnimation(current, SIGN_ADDTION, DURATION);

		TranslateAnimation translateAnimation = new TranslateAnimation(
				Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 0f,
				Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, -1f);
		translateAnimation.setDuration(500);
		translateAnimation.setFillEnabled(true);
		translateAnimation.setFillAfter(true);

		final AlphaAnimation alphaAnimation = new AlphaAnimation(1f, 0f);
		alphaAnimation.setDuration(500);
		alphaAnimation.setStartOffset(500);
		alphaAnimation.setAnimationListener(new AnimationListener() {

			@Override
			public void onAnimationStart(Animation animation) {

			}

			@Override
			public void onAnimationRepeat(Animation animation) {

			}

			@Override
			public void onAnimationEnd(Animation animation) {
				mAddition.setVisibility(View.GONE);
			}
		});

		AnimationSet animationSet = new AnimationSet(true);
		animationSet.addAnimation(translateAnimation);
		animationSet.addAnimation(alphaAnimation);
		animationSet.setInterpolator(new AccelerateInterpolator());
		mAddition.startAnimation(animationSet);
	}

	/**
	 * getOther:(更新other信息). <br/>
	 * 
	 * @author askzhao
	 */
	private void getOther() {
		String customerIdAndToken = PreferenceUtils.getInstance()
				.getcustomerId(mHomeActivity);
		String[] cat = customerIdAndToken.split("&");
		if (cat == null || cat.length < 2)
			return;
		KkdHttpMagager.getInstance().activityConfig(TyjConfigEntity.class,
				new HttpCallBack() {

					@Override
					public void onSuccess(int statusCode, Object responseBody) {
						// 更新数据
						try {
							PreferenceUtils.getInstance().updateHomeOtherData(
									mHomeActivity,
									((TyjConfigEntity) responseBody)
											.getTyjConfig());
						} catch (Exception e) {
							// 忽略
							e.printStackTrace();
						}

					}

					@Override
					public void onFailure(int statusCode, String desc) {
						// 啥也不用做

					}
				});
	}

	/**
	 * 更新UI
	 */
	public void updateUI() {
		if (myProperty.getNewMsgCount() > 0) {
			information_dot.setVisibility(View.VISIBLE);
			information_dot.setText("" + myProperty.getNewMsgCount());
		} else {
			information_dot.setVisibility(View.GONE);
		}

		if (myProperty.getNewMsgCount() > 0
				|| !PreferenceUtils.getInstance().getSystemInformation(
						mHomeActivity)) {
			mHomeActivity.dot.setVisibility(View.VISIBLE);
		} else {
			mHomeActivity.dot.setVisibility(View.GONE);
		}
		appsignRuleUrl = myProperty.getAppsignRuleUrl();
		String url = PreferenceUtils.getInstance().getHeadUrl(mHomeActivity);
		ImageLoader.getInstance().displayImage(url, myproperty_header,
				R.drawable.myproperty_header);
		/*
		 * 设置签到天数
		 */
		sumday = myProperty.getSumday();
		tv_num_day_singed.setText("已签");

		int signInFlag = myProperty.getSignInFlag();
		PreferenceUtils.getInstance().setSignInFlag(mHomeActivity, signInFlag);
		if (PreferenceUtils.getInstance().getSignInFlag(mHomeActivity) == 1) {
			mAddition.setVisibility(View.GONE);
			// mSign.setClickable(false);---改过
			mSign.setText(R.string.signed);
			rel_sign.setVisibility(View.INVISIBLE);
			tv_num_day_singed.setVisibility(View.VISIBLE);
			showHaveSignin = true;
			SIGNINFLAG = false;
			closeAnimation();
			icon_happy_sign.setVisibility(View.GONE);
			icon_happy_sign_positive.setVisibility(View.VISIBLE);
		} else if (PreferenceUtils.getInstance().getSignInFlag(mHomeActivity) == 0) {
			mAddition.setVisibility(View.GONE);
			// mSign.setClickable(true);---改过
			mSign.setText(R.string.sign);
			rel_sign.setVisibility(View.VISIBLE);
			tv_num_day_singed.setVisibility(View.GONE);
			showHaveSignin = false;
			SIGNINFLAG = true;
			setSignInAnimation();
			icon_happy_sign.setVisibility(View.VISIBLE);
			icon_happy_sign_positive.setVisibility(View.GONE);
		}
		if (mAhData != null) {
			String nCardid = "未绑卡";
			if (!TextUtils.isEmpty(mAhData.getCardInfo().getCardNo())) {
				String cardid = mAhData.getCardInfo().getCardNo();
				nCardid = cardid.substring(0, 4)
						+ "********"
						+ cardid.substring(cardid.length() - 4, cardid.length());
			}
			bankid_tv.setText(nCardid);
			discount_count.setText(mAhData.getCouponCount());
			mCurrency.setText(mAhData.getCoinCount());
			mInviteCountTv.setText(mAhData.getInviteIncome());

			if (mAhData.getExperAmount() != null) {
				if (mAhData.getExperAmount().contains(",")) {
					experience_count.setNumber(mAhData.getExperAmount()
							.replaceAll(",", ""));
				} else {
					experience_count.setNumber(mAhData.getExperAmount());
				}
			}
			if (isShowItem) {
				record_count.setText(mAhData.getDqAmount());
				everydaty_count.setText(mAhData.getPlanPrincipal());
				calendar_count.setText(mAhData.getRepayCal());
			} else {
				record_count.setText("****");
				everydaty_count.setText("****");
				calendar_count.setText("****");
			}
			if (mAhData.getIsPlanShow() == 1) {
				mEverydaty.setVisibility(View.VISIBLE);
			} else {
				mEverydaty.setVisibility(View.GONE);
			}
		}

		DecimalFormat df = new DecimalFormat("###,##0.00");
		if (isShowItem) {
			myproperty_icon.setImageResource(R.drawable.myproperty_eye);
			String totalAssets = df.format(myProperty.getTotalAssets());

			String balance = df.format(myProperty.getBalance());
			balance_tv.setText(balance);
			String totalIncome = df.format(myProperty.getTotalIncome());
			earnings_tv.setText(totalIncome);
			if (isPropertyAnimator) {
				property.setText(totalAssets);
				earnings_tv.showNumberWithAnimation(0,
						(float) myProperty.getTotalIncome(), 300);
				isPropertyAnimator = false;
			} else {
				if (property.getText().toString().equals(totalAssets)
						|| property.getText().toString().equals("****")) {
					property.setText(totalAssets);
				} else {
					property.setText(totalAssets);
				}
				if (earnings_tv.getText().toString().equals(totalIncome)
						|| earnings_tv.getText().toString().equals("****")) {
					earnings_tv.setText(totalIncome);
				} else {
					earnings_tv.setText(totalIncome);
					earnings_tv.showNumberWithAnimation(0,
							(float) myProperty.getTotalIncome(), 300);
				}
			}
		} else {
			myproperty_icon
					.setImageResource(R.drawable.myproperty_closeyoureyes);
			property.stopAnimatio();
			property.setText("****");
			balance_tv.setText("****");
			earnings_tv.setText("****");
			mInviteCountTv.setText("****");
		}

		if (!TextUtils.isEmpty(myProperty.getSafetyTips())) {
			safety_tips.setText(myProperty.getSafetyTips());
			safety_line.setVisibility(View.VISIBLE);
			if (DialogUtils.mPopDialog != null) {
				DialogUtils.reLayoutPopDialog(mHomeActivity, true);
			}
		} else {
			safety_line.setVisibility(View.GONE);
			if (DialogUtils.mPopDialog != null) {
				DialogUtils.reLayoutPopDialog(mHomeActivity, false);
			}
		}
	}

	// @Override
	// public boolean onTouch(View v, MotionEvent event) {
	// v.getParent().requestDisallowInterceptTouchEvent(true);// 通知父控件勿拦截
	// return false;
	// }

	public void setSignInAnimation() {
		TranslateAnimation translateAnimation = new TranslateAnimation(
				Animation.RELATIVE_TO_SELF, -1f, Animation.RELATIVE_TO_SELF,
				5f, Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF,
				0f);
		translateAnimation.setDuration(1500);
		translateAnimation.setRepeatCount(Animation.INFINITE);
		translateAnimation.setAnimationListener(new AnimationListener() {

			@Override
			public void onAnimationStart(Animation animation) {
			}

			@Override
			public void onAnimationRepeat(Animation animation) {
			}

			@Override
			public void onAnimationEnd(Animation animation) {

			}
		});

		final AlphaAnimation alphaAnimation = new AlphaAnimation(1f, 0f);
		alphaAnimation.setDuration(1500);
		alphaAnimation.setRepeatCount(Animation.INFINITE);

		AnimationSet mAnimationSet = new AnimationSet(true);
		mAnimationSet.addAnimation(translateAnimation);
		mAnimationSet.addAnimation(alphaAnimation);
		mAnimationSet.setInterpolator(new AccelerateInterpolator());
		// ripple.startAnimation(mAnimationSet);
	}

	public void closeAnimation() {
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.view.View.OnClickListener#onClick(android.view.View)
	 */
	@Override
	public void onClick(View v) {
		Intent intent;
		switch (v.getId()) {

		case R.id.balance_line:
			// 账户余额
			// SystemUtils.onEvent("Account_Blance", 1);
			// intent = new Intent(getActivity(), BalanceActivity.class);
			// startActivity(intent);
			// 交易明细
			SystemUtils.onEvent("Account_TradeDetails", 1);
			intent = new Intent(getActivity(), DealDetailsActivity.class);
			startActivity(intent);
			deal_detail_tv.setVisibility(View.GONE);
			break;
		case R.id.happyBi_rl:// 我的快乐币
			SystemUtils.onEvent("Account_HappyCoin", 1);
			intent = new Intent(getActivity(), MyHappyCoinActivity.class);
			intent.putExtra("mCurrency", mCurrency.getText().toString());
			startActivity(intent);
			if (PreferenceUtils.getInstance().getNewCoin(getActivity())) {
				PreferenceUtils.getInstance().setNewCoin(getActivity(), false);
			}
			break;
		case R.id.experience_rl:
			SystemUtils.onEvent("Account_ExperienceMoney", 1);
			intent = new Intent(getActivity(), MyExperienceGoldActivity.class);
			startActivity(intent);
			break;
		case R.id.earnings_line:// 总收益
			SystemUtils.onEvent("Account_ToastProfit", 1);
			intent = new Intent(getActivity(), MyIncomeActivity.class);
			startActivity(intent);
			break;
		case R.id.property_rl: // 总资产
			SystemUtils.onEvent("Account_ToastAssets", 1);
			intent = new Intent(getActivity(), MyTotalAssetsActivity.class);
			startActivity(intent);
			break;
		case R.id.property_eye: // 总资产
			showOrDismissItem();
			break;
		case R.id.record: // 定期
			SystemUtils.onEvent("Account_Regular", 1);
			intent = new Intent(getActivity(), MyRegularDebtActivity.class);
			getActivity().startActivityForResult(intent, 200);
			break;

		case R.id.safety_line:// 投资前准备
		case R.id.bank_card_rl:// 银行卡管理
			SystemUtils.onEvent("Account_BankCard", 1);
			// if (PreferenceUtils.getInstance().getBoundBankCard(getActivity())
			// == 1) {
			// intent = new Intent(getActivity(), MyBlockActivity.class);
			// startActivity(intent);
			// } else {
			// intent = new Intent(getActivity(), ForTenderActivity.class);
			// intent.putExtra("isShowDialogTip", false);
			// intent.putExtra("enterTypeFlag", 1);
			// startActivity(intent);
			// }

			if (PreferenceUtils.getInstance().getOpenAccount(getActivity()) != 1) {
				intent = new Intent(getActivity(), ForTenderActivity.class);
				intent.putExtra("isShowDialogTip", false);
				intent.putExtra("enterTypeFlag", 1);
				startActivity(intent);
			} else {
				if (PreferenceUtils.getInstance().getBoundBankCard(
						getActivity()) == 1) {
					intent = new Intent(getActivity(), MyBlockActivity.class);
					startActivity(intent);
				} else {
					intent = new Intent(getActivity(),
							BindBankCardActivity.class);
					intent.putExtra("isShowDialogTip", false);
					intent.putExtra("enterTypeFlag", 1);
					startActivity(intent);
				}
			}
			break;
		case R.id.withdraw_bt: // 提现
			SystemUtils.onEvent("Account_WithDraw", 1);
			if (PreferenceUtils.getInstance().getAutonym(getActivity()) == 1) {
				if (PreferenceUtils.getInstance().getBoundBankCard(
						getActivity()) == 1) {

					intent = new Intent(getActivity(), WithdrawActivity.class);
					startActivity(intent);

				} else {
					intent = new Intent(getActivity(), ForTenderActivity.class);
					intent.putExtra("enterTypeFlag", 2);
					startActivity(intent);
				}
			} else {
				intent = new Intent(getActivity(), ForTenderActivity.class);
				intent.putExtra("enterTypeFlag", 2);
				startActivity(intent);
			}
			break;
		case R.id.recharge_bt: // 充值
			SystemUtils.onEvent("Account_Recharge", 1);
			if (AppUtil.isConnect(getActivity())) {
				if (PreferenceUtils.getInstance().getAutonym(getActivity()) == 1) {
					if (PreferenceUtils.getInstance().getBoundBankCard(
							getActivity()) == 1) {
						intent = new Intent(getActivity(),
								RechargeActivity.class);
						startActivity(intent);
					} else {
						intent = new Intent(getActivity(),
								ForTenderActivity.class);
						intent.putExtra("enterTypeFlag", 3);
						startActivity(intent);
					}
				} else {
					intent = new Intent(getActivity(), ForTenderActivity.class);
					intent.putExtra("enterTypeFlag", 3);
					startActivity(intent);
				}
			} else {
				showToast(R.string.network_anomaly);
			}
			break;
		case R.id.tv_iknow:
			if (mDialog_signin != null) {
				mDialog_signin.dismiss();
			}
			onSignClick();
			mHomeActivity.mymanage();
			break;
		case R.id.tv_rule:
			if (mDialog_signin != null) {
				mDialog_signin.dismiss();
			}
			// mSign.setClickable(false);---改过
			// mSign.setBackgroundResource(R.drawable.domyproperty_sign);
			mSign.setText(R.string.signed);
			rel_sign.setVisibility(View.INVISIBLE);
			tv_num_day_singed.setVisibility(View.VISIBLE);
			showHaveSignin = true;
			mHomeActivity.mymanage();
			intent = new Intent(getActivity(), HowToHappyCoinActivity.class);
			startActivity(intent);
			break;
		case R.id.myproperty_top_img: // 头像
		case R.id.tequan_tip:
			SystemUtils.onEvent("Account_Set", 1);
			PrivilegeModel.updateShownById();// 将特权tip的显示状态改为已显示过
			tequan_tip.setVisibility(View.GONE);
			intent = new Intent(getActivity(), MyActivity.class);
			getActivity().startActivityForResult(intent, 400);
			break;
		case R.id.symbol: // 消息中心
			SystemUtils.onEvent("Account_Message", 1);
			intent = new Intent(getActivity(), InformationActivity.class);
			startActivity(intent);
			break;
		case R.id.everydaty_rl: // 天天赚
			SystemUtils.onEvent("Account_Current", 1);
			intent = new Intent(getActivity(), MyPlanActivity.class);
			startActivity(intent);
			break;
		case R.id.discount: // 我的优惠券
			SystemUtils.onEvent("Account_Coupon", 1);
			intent = new Intent(getActivity(), MyDiscountCouponActivity.class);
			startActivity(intent);
			break;
		case R.id.tv_num_day_singed:// 已签到
			if (!TextUtils.isEmpty(appsignRuleUrl)) {
				SystemUtils.onEvent("Account_UnCheckIN", 1);
				intent = new Intent(getActivity(), KKDWebActivity.class);
				intent.putExtra("titleName", "签到");
				intent.putExtra("url", appsignRuleUrl);
				startActivity(intent);
			}
			break;
		case R.id.invite_friends: // 邀请好友
			SystemUtils.onEvent("Discovery_InviteFrinds", 1);
			intent = new Intent(getActivity(), MyRecommendFriendActivity.class);
			startActivityForResult(intent, 106);
			break;
		case R.id.calendar_bt: // 还款日历
			intent = new Intent(getActivity(), CalendarActivity.class);
			startActivity(intent);
			break;

		}

	}

	private boolean isShowItem = true;

	public void showOrDismissItem() {
		isShowItem = !isShowItem;
		PreferenceUtils.getInstance().setIsShowMyproperty(mHomeActivity,
				isShowItem);
		updateUI();
	}

	public void showToast(Activity acitivity, String hintLanguage) {
		AppUtil.makeToastForCustomer(acitivity, hintLanguage);
	}

	private void iconFilp() {
		flip = ObjectAnimator.ofFloat(icon_happy_sign, "rotationY", 0f, 180f);
		flip.setDuration(2000);
		flip.setRepeatCount(Animation.INFINITE);
		flip.start();
		PropertyValuesHolder pvhX = PropertyValuesHolder.ofFloat("alpha", 1f,
				0f);
		float scx = icon_happy_sign.getScaleX() >= 1 ? 1 : icon_happy_sign
				.getScaleX();
		float scy = icon_happy_sign.getScaleY() >= 1 ? 1 : icon_happy_sign
				.getScaleY();
		PropertyValuesHolder pvhY = PropertyValuesHolder.ofFloat("scaleX", scx,
				2 * scx);
		PropertyValuesHolder pvhZ = PropertyValuesHolder.ofFloat("scaleY", scy,
				2 * scy);
	}

	public void showToast(int hintLanguage) {

		AppUtil.makeToastForCustomer(getActivity(), hintLanguage);
	}

	/**
	 * showExperienceCountAnimation:(这里用一句话描述这个方法的作用). <br/>
	 * 
	 * @author askzhao
	 */
	public void showExperienceCountAnimation() {
		experience_count.showNumberWithAnimation(
				0,
				(int) Double.parseDouble(mAhData.getExperAmount().replaceAll(
						",", "")), 300);
	}

	/**
	 * requestAnimation:(这里用一句话描述这个方法的作用). <br/>
	 * 
	 * @author askzhao
	 */
	public void requestAnimation() {
		if (myProperty != null && earnings_tv != null) {
			earnings_tv.showNumberWithAnimation(0,
					(float) myProperty.getTotalIncome(), 300);
		}
	}

	public void ScrollToTop() {
		mScrollView.fullScroll(ScrollView.FOCUS_UP);
	}

	// private OnClickListener getOnClickListener() {
	// if (null == mOnClickListener) {
	// mOnClickListener = new View.OnClickListener() {
	// @Override
	// public void onClick(View v) {
	// explosionField.explode(v);
	// if (SIGNINFLAG) {
	// signIn();
	// }
	// }
	// };
	// }
	// return mOnClickListener;
	// }

	/*************
	 * 我的特权接口
	 *************/
	public void queryPrivilege() {
		if (PreferenceUtils.getInstance().getLogin(mHomeActivity) != 0)
			return;
		KkdHttpMagager.getInstance().queryPrivilege(new HttpCallBack() {

			@Override
			public void onSuccess(int statusCode, Object responseBody) {
				mHandler.sendEmptyMessage(ON_GOT_PRIVILEGE);
			}

			@Override
			public void onFailure(int statusCode, String desc) {

			}
		});
	}

	/**
	 * 拨打客服电话对话框
	 * 
	 * @param message
	 */
	private void showDialog(String message) {
		if (dialog_service != null) {
			dialog_service.cancel();
			dialog_service = null;
		}
		dialog_service = DialogUtils.callService(mHomeActivity);
		dialog_service.show();
	}

}